from time import sleep,strftime
from concurrent import futures

def display(*args):
    print(strftime("[%H:%M:%S]"),end='')
    print(*args)

def loiter(n):
    msg = '{}loiter({}): doing nothing for {}s...'
    display(msg.format('\t'*n, n, n))
    sleep(n)
    msg = '{}loiter({}): done.'
    display(msg.format('\t'*n, n))
    return n * 10

def main():
    display("Script starting.")
    executor = futures.ThreadPoolExecutor(3) #设置最大线程数是3
    results = executor.map(loiter,range(5)) #想并发调用5个 那么前三个可以立即执行 余下的需要等到其他线程执行完有空闲线程才执行
    display('display:',results)
    display('Waiting for individual results:')
    for i,result in enumerate(results):
        display('result {}: {}'.format(i, result))

main()

import collections

counter = collections.Counter({"age":"2","name":"zhou"}) #计算各个元素出现的次数
print(counter)

